home *** CD-ROM | disk | FTP | other *** search
- // Avi's Balloon Previewer
- // by Avi Drissman <mailto:drissman@acm.org>
- // with a hell of a lot of help from Marshall Clow and Leonard Rosenthal
- // addl thanks to Eric Traut, Chris Russ
-
- #include <SetUpA4.h>
- #include <A4Stuff.h>
- #include <Errors.h>
- #include <Balloons.h>
-
- #include "formats.h"
-
- typedef pascal void (*BalloonsProcPtr) ();
- #define callBalloons(userRoutine) \
- (*(BalloonsProcPtr)(userRoutine))()
-
- //prototypes
- //static asm void saveregisters (void);
- //static asm void restoreregisters (void);
- static pascal OSErr MyBalloons(ResType inType,
- SInt16 inResID,
- SInt16 inMessageIndex,
- SInt16 inMessageState,
- HMMessageRecord * outMessage,
- OSErr trapResult );
- static asm void checkconditions(void);
- static asm void originaladdress(void);
-
- pascal void ShowInitIcon( short iconId, Boolean advance);
-
- pascal void main()
- {
- Handle initHandle;
- // OSErr err;
-
- // if (Button())
- // return;
-
- // EnterCodeResource();
- // PrepareCallback(); // setup a4 for later usage!
-
- /* Locate this resource in memory and detach it */
- initHandle = Get1Resource('INIT', 0);
- HLock(initHandle);
- HNoPurge(initHandle);
- DetachResource(initHandle);
-
- long * saver = (long*)(&originaladdress);
-
- *saver = (long)NGetTrapAddress(_Pack14, ToolTrap);
- ++saver;
- *saver = (long)MyBalloons;
-
- // *((long*)(&originaladdress)) = (long)NGetTrapAddress(_Pack14, ToolTrap);
- // *(((long*)(&originaladdress)) + 1) = (long)MyBalloons;
- // gBalloonsAddress = (long)NGetTrapAddress(_Pack14, ToolTrap);
- NSetTrapAddress((UniversalProcPtr)checkconditions, _Pack14, ToolTrap);
-
- ShowInitIcon(128, true);
-
- // ExitCodeResource();
- }
-
- static pascal OSErr MyBalloons(ResType inType,
- SInt16 /*inResID*/,
- SInt16 /*inMessageIndex*/,
- SInt16 /*inMessageState*/,
- HMMessageRecord * outMessage,
- OSErr trapResult )
- {
- // DebugStr("\pIn C patch.. Damn!");
-
- // Debugger();
-
- // Only for file balloons
- if (inType != kHMFinderApplResType)
- return trapResult;
-
- Handle pnotH = Get1IndResource('pnot', 1);
-
- // We need a preview
- if (ResError() != noErr)
- return trapResult;
-
- pnotStruct** thePnotH = reinterpret_cast<pnotStruct**>(pnotH);
-
- // A _picture_ preview
- if (thePnotH [0]-> resType != 'PICT')
- return trapResult;
-
- short pictID = thePnotH [0]-> resID;
-
- ReleaseResource (pnotH);
-
- outMessage -> hmmHelpType = khmmPict;
- outMessage -> u.hmmPict = pictID;
-
- return noErr;
- }
-
- /*static asm void saveregisters (void)
- {
- move.l (sp)+,a0 // the return address in a0
- movem.l d0-d2/a1,-(sp) // which is not saved
- jmp (a0)
- }
-
- static asm void restoreregisters (void)
- {
- move.l (sp)+,a0 // the return address in a0
- movem.l (sp)+,d0-d2/a1 // which is not restored
- jmp (a0)
- }
- */
- static asm void checkconditions(void)
- {
- cmp.w #0x0711, d0
- beq.w yup
- lea originaladdress, a0
- move.l (a0), a0
- jmp (a0)
- yup:
- // _Debugger
- // Make a copy of the params
- move.l 0x10(A7), -(A7)
- move.l 0x10(A7), -(A7)
- move.l 0x10(A7), -(A7)
- move.l 0x10(A7), -(A7)
- // call the orginal trap, and return to "returnHere"
- pea returnHere
- lea originaladdress, a0
- move.l (a0), a0
- jmp (a0)
-
-
- returnHere:
- // _Debugger
- move.w (A7)+, D0 // return value
- move.w D0, 0x12(A7) // put it where the caller expects
- beq.s getOut // if there was no error, we're done
-
- move.l (A7)+, A0 // return address
- move.w D0, -(A7) // the result from the
- move.l a0, -(A7)
- lea originaladdress, a0 // MyBalloons
- move.l 4(a0), a0
- jmp (a0)
-
- getOut:
- rtd #0x0E
- }
-
- static asm void originaladdress(void)
- {
- _Debugger
- _Debugger
- _Debugger
- _Debugger
- }